package com.mes.service.warehouse;

import com.yy.base.common.dao.Dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class XbkXjListService {
    @Autowired
    private Dao dao;
    //根据作业工单号查询信息
    public List<Map<String,Object>> selectXbkPlanListByCode(String code) {
        String sql = "select * from Emeso_Job_Order plan where plan.code = ? " ;

        return dao.query(sql,code);
    }

    //根据物料号查询信息
    public List<Map<String,Object>> selectXbkProductListByCode(String code) {
        String sql = "SELECT  " +
                "  fl.VALUE  AS FLVALUE,  " +
                "  fl.NAME AS FLNAME,  " +
                "  wl.VALUE AS WLVALUE,  " +
                "  wl.NAME AS WLNAME,  " +
                "  to_char ( now( ), 'yyyy-mm-dd hh24:mi:ss' ) AS TIMES   " +
                "FROM  " +
                "  m_product wl,  " +
                "  m_product_category fl   " +
                "WHERE  " +
                "  wl.m_product_category_id = fl.m_product_category_id " +
                " and wl.value = ? " ;

        return dao.query(sql,code);
    }

    //查询鞋面辅料MES参数
    public List<Map<String,Object>> selectMesParameter(String code) {
        String sql = " select cs.value as CSVALUE from Emes_Parameter cs where cs.code = ?  " ;

        return dao.query(sql , code);
    }


    //根据物料ID查询对应仓库
    public List<Map<String,Object>> selectWarehouseCode(String id) {
        String sql = " select ck.shipper_code as CKCODE from wms_warehouse_product wl , m_warehouse ck  " +
                " where wl.m_warehouse_id = ck.m_warehouse_id " +
                " and wl.m_product_id = ? " ;

        return dao.query(sql,id);
    }


    //根据传过来的RFID号查询item表中是否存在RFID
    public List<Map<String,Object>> getBatchnorLists(String batch_no) {

        return dao.query("SELECT  \n" +
                "   mx.wms_storage_batch_item_id as ITEMID,   \n" +
                " wl.m_product_id as WLID, wl.value as WLVALUE, wl.name as WLNAME,to_char(now(), 'yyyy-mm-dd hh24:mi:ss') as TIMES, \n" +
                " pc.emes_size_id as CMID , mx.status as STATUS \n" +
                "FROM  \n" +
                " wms_storage_batch pc,  \n" +
                " m_product wl ,  \n" +
                " wms_storage_batch_item mx  \n" +
                "WHERE  \n" +
                " pc.m_product_id = wl.m_product_id  \n" +
                " and pc.wms_storage_batch_id = mx.wms_storage_batch_id  \n" +
                " and mx.code = '"+batch_no+"'  \n" +
                " group by   wl.m_product_id ,   pc.emes_size_id  ,mx.status ,mx.wms_storage_batch_item_id,wl.name ");
    }

}
